package ui.panels;

import entities.User;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import manager.DepartmentHeadDriver;
import model.ViewHeadSchedulerInDepTableModel;
import model.ViewHeadSchedulerTableModel;
import ui.windows.RemedySchedulerFrame;

public class ViewHeadScheduler extends javax.swing.JPanel {

    /** Creates new form ViewHeadScheduler */
    public ViewHeadScheduler(RemedySchedulerFrame mainFrame) {
        initComponents();
        this.mainFrame = mainFrame;
        driver = (DepartmentHeadDriver) mainFrame.getDriver();
        includeModel();
    }

    private void includeModel() {
        User user = mainFrame.getUser();
        schedulerTableModel = new ViewHeadSchedulerInDepTableModel(driver.showViewHeadScheduler(user.getUserID(), user.getDepartmentID()));
        schedulerTable.setModel(schedulerTableModel);
        schedulerTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        schedulerTable.setFillsViewportHeight(true);
        schedulerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        schedulerTable.getTableHeader().setFont(new Font(null, Font.BOLD, 10));
        DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer();
        cellRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
        cellRenderer.setBackground(Color.yellow);
        DefaultTableCellRenderer cellRenderer1 = new DefaultTableCellRenderer();
        cellRenderer1.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
        cellRenderer1.setBackground(new Color(100, 50, 102));
        cellRenderer1.setForeground(new Color(240, 240, 240));
        schedulerTable.getColumnModel().getColumn(0).setPreferredWidth(70);
        schedulerTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        schedulerTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        schedulerTable.getColumnModel().getColumn(2).setCellRenderer(cellRenderer);
        schedulerTable.getColumnModel().getColumn(3).setPreferredWidth(100);
        schedulerTable.getColumnModel().getColumn(3).setCellRenderer(cellRenderer1);
        schedulerTable.getColumnModel().getColumn(4).setPreferredWidth(120);
        schedulerTable.getColumnModel().getColumn(5).setPreferredWidth(120);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private RemedySchedulerFrame mainFrame;
    private DepartmentHeadDriver driver;
    private ViewHeadSchedulerInDepTableModel schedulerTableModel;
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        schedulerTable = new javax.swing.JTable();

        setBackground(new java.awt.Color(255, 255, 255));

        schedulerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(schedulerTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 558, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable schedulerTable;
    // End of variables declaration//GEN-END:variables
}
